package com.example.home_module;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewbinding.ViewBinding;

import com.example.common.field.DataActionEntity;
import com.example.common.mvvm.view.BaseFragment;
import com.example.home_module.databinding.VideoFragmentBinding;
import com.example.home_module.entity.VideoEntity;
import com.example.home_module.entity.VideoValuesEntity;

import java.util.ArrayList;
import java.util.List;

public class VideoFragment extends BaseFragment<VideoFragmentBinding,VideoViewModel> {
    VideoAdapter videoAdapter=new VideoAdapter();

    List<VideoValuesEntity> data = new ArrayList<>();
    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBinding() {
        return VideoFragmentBinding.inflate(inflater);

    }

    @Override
    public void initView() {
        v.recyc.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    @Override
    public void initData() {
         v.recyc.setAdapter(videoAdapter);
         vm.getUiDataFunction().getUiData().observe(this, new Observer<DataActionEntity>() {
        @Override
        public void onChanged(DataActionEntity entity) {
            if (entity.action.equals("dsy")) {

                data = (List<VideoValuesEntity>) entity.data.get("data");
                videoAdapter.setNewInstance(data);
                videoAdapter.notifyDataSetChanged();
                Log.i("dataSize", "onChanged: "+data.size());

            }
        }
    });
    }
}